package com.example.controller;

import com.example.pojo.Emp;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.pojo.Wages;
import com.example.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result selectAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize,
                            String name, @RequestParam(defaultValue = "0") int departmentID,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageBean pageBean = empService.page(page, pageSize, name, departmentID, begin, end);
        return Result.success(pageBean);
    }
    @GetMapping("/some")
    public Result selectSomeOne(){
        List<Emp> empList = empService.select();
        return Result.success(empList);
    }

    @GetMapping("/aa")
    public Result selectSomeOnes(){
        String empList = empService.selects();
        return Result.success(empList);
    }
    @PostMapping
    public Result add(@RequestBody Emp emp) {
        empService.add(emp);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result deletes(@PathVariable List<Integer> ids) {
        empService.deletes(ids);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Emp emp) {
        empService.update(emp);
        return Result.success();
    }
    @PostMapping("/wages")
    public Result wages(@RequestBody Wages wages){
        empService.wages_get(wages);
        return Result.success();
    }
}
